<template>
  <div>
    <div
      style="
        font-size: 16px;
        font-weight: 600;
        color: #1d2129;
        margin-bottom: 16px;
      "
    >
      青少年体育经费-支出
    </div>
    <div style="display: flex">
      <div style="width: 50%">
        <div style="font-size: 26px; color: #41b776">34,201</div>
        <div style="font-size: 12px">经费支出（万元）</div>
      </div>
    </div>
    <div style="display: flex; width: 100%; margin-left: -10%; margin-top: 10%">
      <div ref="chart" style="width: 50%; height: 229px"></div>
      <div
        style="
          width: 50%;
          height: 129px;
          padding: 2px 10px;
          margin-top: 8%;
          display: flex;
          flex-wrap: wrap;
          justify-content: space-between;
        "
      >
        <div style="display: flex" v-for="(item, index) in namedata">
          <div :style="{ backgroundColor: item.color }" class="dianidan"></div>
          <div>
            <div style="font-size: 12px; margin-right: 7px; width: 61px">
              {{ item.name }}
            </div>
            <div style="font-size: 22px; color: #0f0f0f">
              {{ item.value }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import * as echarts from "echarts";
import { getSheet1MoneyData2 } from "@/api/statistics";
export default {
  data() {
    return {
      date: new Date().getFullYear(),
      activeTab: 1,
      namedata: [
        { name: "业余训练", value: 100, color: "#4E88F5" },
        { name: "青少年组织", value: 100, color: "#EEB74A" },
        { name: "竞赛与活动组织", value: 100, color: "#41B776" },
        { name: "学校场馆开放", value: 100, color: "#F59E4E" },
        { name: "其他", value: 100, color: "#F59E4E" },
      ],
    };
  },

  mounted() {
    this.datalist();
  },
  methods: {
    async datalist(e) {
      const res = await getSheet1MoneyData2({
        year: this.date,
      });
      if (res.data) {
        console.log(res.data);
      }
      // const series = res.data.series;
      // const xAxis = res.data.xAxis;
      // 基于准备好的dom，初始化echarts实例
      this.chart = echarts.init(this.$refs.chart);

      // 指定图表的配置项和数据
      const option = {
        title: {
          text: "3326",
          left: "center",
          top: "42%",
          textStyle: {
            color: "#333",
            fontSize: 15,
            align: "center",
          },
        },
        tooltip: {
          trigger: "item",
        },

        legend: {
          top: "5%",
          left: "center",
          show: false,
        },
        series: [
          {
            type: "pie",
            radius: ["40%", "70%"],
            avoidLabelOverlap: false,
            label: {
              show: false,
              position: "center",
            },
            radius: ["65%", "80%"],

            labelLine: {
              show: false,
            },
            data: this.namedata,
          },
        ],
      };

      // 使用刚指定的配置项和数据显示图表。
      this.chart.setOption(option);

      // 监听父元素大小变化 刷新图表
      var ro = new ResizeObserver((entries) => {
        for (let entry of entries) {
          const cr = entry.contentRect;
          this.chart.resize();
        }
      });

      ro.observe(this.$refs.chart);
    },
  },
};
</script>

<style>
.dianidan {
  width: 7px;
  height: 7px;
  margin-right: 5px;
}
</style>
